using System.Collections.Generic;
using System.IO;
using MvcRags.Examples.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace MvcRags.Examples.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<MvcRags.Examples.Models.ExampleDataContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(MvcRags.Examples.Models.ExampleDataContext context)
        {
            string testDataJson = Properties.Resources.TestCustomers;
            IEnumerable<JObject> testData = JsonConvert.DeserializeObject<IEnumerable<JObject>>(testDataJson);
            foreach (JObject o in testData)
            {
                Customer newCustomer = new Customer();
                newCustomer.Pvn = (int) o.SelectToken("PVN");
                newCustomer.Country = (string) o.SelectToken("Country");
                newCustomer.Mail = (string) o.SelectToken("Email");
                newCustomer.Name = (string) o.SelectToken("Full Name");
                newCustomer.CreatedAt = (DateTime) o.SelectToken("Created At");
                context.Customers.Add(newCustomer);
            }
        }
    }
}
